package fr.zadoka.zadokadna.Connectivity;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

public class UrlImageLoader {
	
	public UrlImageLoader()
	{
	}
	
	public Bitmap getImage(String imageUrl)
	{
		HttpURLConnection connection = new ZadokaServerConnection().getConnection(imageUrl);
		
		if (connection == null)
			return null;
		
		Bitmap bitmap = getImage(connection);
		
		connection.disconnect();
		
		return bitmap;
	}
	
	
	public Bitmap getImage(HttpURLConnection connection)
	{
		if (connection == null)			
			return null;
		
		try {
			InputStream in = connection.getInputStream();
			Bitmap imageData =  BitmapFactory.decodeStream(in);
			in.close();
	        return imageData;
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
			return null;
		}				
	}	
}